package com.ruoyi.college.service.impl;

import java.util.List;

import com.ruoyi.college.domain.Course;
import com.ruoyi.college.domain.CourseArrangement;
import com.ruoyi.college.domain.Teacher;
import com.ruoyi.college.service.ICourseArrangementService;
import com.ruoyi.college.service.ICourseService;
import com.ruoyi.college.service.ITeacherService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.college.mapper.CourseTeacherMapper;
import com.ruoyi.college.domain.CourseTeacher;
import com.ruoyi.college.service.ICourseTeacherService;
import com.ruoyi.common.core.text.Convert;

/**
 * 授课老师安排Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-26
 */
@Service
public class CourseTeacherServiceImpl implements ICourseTeacherService 
{
    @Autowired
    private CourseTeacherMapper courseTeacherMapper;

    @Autowired
    private ICourseArrangementService  courseArrangementService;

    @Autowired
    private ICourseService courseService;

    @Autowired
    private ITeacherService teacherService;

    /**
     * 查询授课老师安排
     * 
     * @param id 授课老师安排主键
     * @return 授课老师安排
     */
    @Override
    public CourseTeacher selectCourseTeacherById(Long id)
    {
        return courseTeacherMapper.selectCourseTeacherById(id);
    }

    /**
     * 查询授课老师安排列表
     * 
     * @param courseTeacher 授课老师安排
     * @return 授课老师安排
     */
    @Override
    public List<CourseTeacher> selectCourseTeacherList(CourseTeacher courseTeacher)
    {
        List<CourseTeacher> courseTeachers = courseTeacherMapper.selectCourseTeacherList(courseTeacher);
        courseTeachers.forEach(item->{
            Long arrangementId = item.getArrangementId();
            CourseArrangement courseArrangement = courseArrangementService.selectCourseArrangementByArrangementId(arrangementId);
            Long courseId = courseArrangement.getCourseId();
            Course course = courseService.selectCourseByCourseId(courseId);
            item.setCourseId(courseId);
            item.setCourseName(course.getCourseName());
            Long teacherId = item.getTeacherId();
            Teacher teacher = teacherService.selectTeacherByTeacherId(teacherId);
            item.setTeacherName(teacher.getTeacherName());
        });
        return courseTeachers;
    }

    /**
     * 新增授课老师安排
     * 
     * @param courseTeacher 授课老师安排
     * @return 结果
     */
    @Override
    public int insertCourseTeacher(CourseTeacher courseTeacher)
    {
        courseTeacher.setCreateTime(DateUtils.getNowDate());
        return courseTeacherMapper.insertCourseTeacher(courseTeacher);
    }

    /**
     * 修改授课老师安排
     * 
     * @param courseTeacher 授课老师安排
     * @return 结果
     */
    @Override
    public int updateCourseTeacher(CourseTeacher courseTeacher)
    {
        return courseTeacherMapper.updateCourseTeacher(courseTeacher);
    }

    /**
     * 批量删除授课老师安排
     * 
     * @param ids 需要删除的授课老师安排主键
     * @return 结果
     */
    @Override
    public int deleteCourseTeacherByIds(String ids)
    {
        return courseTeacherMapper.deleteCourseTeacherByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除授课老师安排信息
     * 
     * @param id 授课老师安排主键
     * @return 结果
     */
    @Override
    public int deleteCourseTeacherById(Long id)
    {
        return courseTeacherMapper.deleteCourseTeacherById(id);
    }
}
